import {
  getDictionary,
  uploadFile,
  bindFileUrl,
  getUserList,
  getDeptList,
  docProduct,
  delDoc,
  organizerList,
  nameList,
  placeInfoList,
  generatePunishOnTheSpotDecision
} from '@/api/public'

export default defineStore('usePublic', {
  state: () => ({}),
  getters: {},
  actions: {
    //获取数据字典数据
    async getDictionary(params) {
      let url = $globalRequestUrl({
        url: getDictionary + `/${params}`,
      })
      try {
        const rep = await $globalRequest(url, {}, { method: 'GET' })
        return rep
      } catch (error) {
        return error
      }
    },

    //文件上传
    async uploadFile(file, fileType) {
      let url = $globalRequestUrl({
        url: uploadFile + `/${fileType}`,
      })
      try {
        const rep = await $globalRequest(url, file, { method: 'POST_FORMDATA' })
        return rep
      } catch (error) {
        return error
      }
    },

    //签名上传--特殊处理
    async uploadFile2(content) {
      let url = $globalRequestUrl({
        url: uploadFile,
      })
      try {
        const rep = await $globalRequest(url, content, { method: 'POST' })
        return rep
      } catch (error) {
        return error
      }
    },

    //绑定文件路径
    async bindFileUrl(fileUrl) {
      let url = $globalRequestUrl({
        url: bindFileUrl + `?fileUrl=${fileUrl}`,
      })
      try {
        const rep = await $globalRequest(url, {}, { method: 'GET' })
        return rep
      } catch (error) {
        return error
      }
    },

    //根据执法机构id查询用户列表
    async getUserList(deptId, userType) {
      let url = $globalRequestUrl({
        url: getUserList + `/${deptId}/${userType}`,
      })
      try {
        const rep = await $globalRequest(url, {}, { method: 'GET' })
        return rep
      } catch (error) {
        return error
      }
    },

    //获取执法机构下拉框列表
    async getDeptList() {
      let url = $globalRequestUrl({
        url: getDeptList,
      })
      try {
        const rep = await $globalRequest(url, {}, { method: 'GET' })
        return rep
      } catch (error) {
        return error
      }
    },

    //任务中的文书的制作
    async docProduct(params) {
      let url = $globalRequestUrl({
        url: docProduct,
      })
      try {
        const rep = await $globalRequest(url, params, { method: 'POST' })
        return rep
      } catch (error) {
        return error
      }
    },
    async generatePunishOnTheSpotDecision(params) {
      let url = $globalRequestUrl({
        url: generatePunishOnTheSpotDecision,
      })
      try {
        const rep = await $globalRequest(url, params, { method: 'POST' })
        return rep
      } catch (error) {
        return error
      }
    },


    //删除任务中的文书
    async delDoc(params) {
      let url = $globalRequestUrl({
        url: delDoc + `/${params.type}/${params.taskId}`,
      })
      try {
        const rep = await $globalRequest(url, {}, { method: 'GET' })
        return rep
      } catch (error) {
        return error
      }
    },

    //获取协办人列表
    async getOrganizer() {
      let url = $globalRequestUrl({
        url: organizerList,
      })
      try {
        const rep = await $globalRequest(url, {}, { method: 'GET' })
        return rep
      } catch (error) {
        return error
      }
    },

    //获取场所列表
    async getNameList(params) {
      let url = $globalRequestUrl({
        url: nameList + `?placeName=${params}`,
      })
      try {
        const rep = await $globalRequest(url, {}, { method: 'GET' })
        return rep
      } catch (error) {
        return error
      }
    },

    //获取场所信息
    async getPlaceInfo(id) {
      let url = $globalRequestUrl({
        url: placeInfoList + `/${id}`,
      })
      try {
        const rep = await $globalRequest(url, {}, { method: 'GET' })
        return rep
      } catch (error) {
        return error
      }
    },
  },
})
